﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ScoreMS.Model;

namespace ScoreMS.BLL
{
    public class Course_syllabusBS
    {
        /// <summary>
        /// 获取指定课程的教学大纲列表
        /// </summary>
        /// <param name="teacher_id"></param>
        /// <returns></returns>
        static public List<Course_syllabus> GetCourse_syllabusList(string course_id)
        {
            using (scoremsdbEntities db = new scoremsdbEntities())
            {
                var ret = db.course_syllabus.Where(x => x.course_id == course_id).OrderBy(c => c.syllabus_index);
                List<Course_syllabus> list = new List<Course_syllabus>();
                foreach (var c in ret)
                {
                    Course_syllabus model = new Course_syllabus();
                    model.course_id = c.course_id;
                    model.syllabus_index = c.syllabus_index;
                    model.syllabus_descr = c.syllabus_descr;
                    list.Add(model);
                }
                return list;
            }
        }


        /// <summary>
        /// 为课程添加教学大纲
        /// </summary>
        /// <param name="course_id">课程ID</param>
        /// <param name="syllabus_descr">大纲条目描述</param>
        /// <returns></returns>
        static public bool AddCourse_syllabus(string course_id, string syllabus_descr)
        {
            try
            {
                using (scoremsdbEntities db = new scoremsdbEntities())
                {
                    //条目编号为当前最大编号+1
                    int syllabus_index = 1 + db.course_syllabus.Where(x => x.course_id == course_id).Max(c => c.syllabus_index);
                    db.course_syllabus.AddObject(new course_syllabus()
                    {
                        syllabus_index = syllabus_index,
                        syllabus_descr = syllabus_descr,
                        course_id = course_id
                    });
                    db.SaveChanges();
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
        /// <summary>
        /// 为课程添加教学大纲
        /// </summary>
        /// <param name="course"></param>
        /// <returns>成功返回true</returns>
        static public bool AddCourse_syllabus(Course_syllabus model)
        {
            try
            {
                using (scoremsdbEntities db = new scoremsdbEntities())
                {
                    //条目编号为当前最大编号+1
                    int syllabus_index = 1 + db.course_syllabus.Where(x => x.course_id == model.course_id).Max(c => c.syllabus_index);
                    db.course_syllabus.AddObject(new course_syllabus()
                    {
                        syllabus_index = syllabus_index,  //!!
                        syllabus_descr = model.syllabus_descr,
                        course_id = model.course_id
                    });
                    db.SaveChanges();
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
